<?php

/**
 *   OPENSHOP 管理中心商品参数管理
 * 
 *   @link        http://baison.com.cn
 *   @copyright   Baison, Inc.
 *   @package     OpenShop
 *   @version     $Id: goods_params.php,v 1.0 $
 *   @author      baison <bs>
 */

define('IN_OS', true);

require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . 'includes/lib_main.php');

$exc = new exchange($os->table('goods'), $db, 'goods_id', 'goods_name');

/*------------------------------------------------------ */
//-- 设置商品参数
/*------------------------------------------------------ */

if($_REQUEST['act'] == 'insert') {
	$act_range             = intval($_POST['act_range']);
    $act_range_ext         = intval($_POST['act_range']) == 0 ? '' : join(',', $_POST['act_range_ext']);
    $exclude_range         = intval($_POST['exclude_range']);
    $exclude_range_ext     = intval($_POST['exclude_range']) == 0 ? '' : join(',', $_POST['exclude_range_ext']);
    //取得检索条件
    $hot_search_condition  = get_hot_search_condition($act_range, $act_range_ext, $exclude_range, $exclude_range_ext);
    //设置更新字段
    $goods_params = get_goods_params();
    $set_str = " SET ";
    foreach($goods_params as $key => $val) {
    	if($_POST[$val['name'].'_or_not']) {
    		if($_POST[$val['name'].'_or_clear']) { $set_str .= $val['name'] . "='" . $_POST[$val['name']] . "',"; }
    		else { $set_str .= $val['name'] . "='0',"; }
    	}
    }
    $set_str = preg_replace("/,$/", ' ', $set_str);
    if(!empty($set_str) && $set_str != " SET ") {
	    if($GLOBALS['db']->query("UPDATE " . $GLOBALS['os']->table('goods') . " $set_str WHERE 1=1 $hot_search_condition ")) {
	    	sys_msg('批量设置商品参数成功。');
	    } else {
	    	sys_msg('数据库操作错误，请联系管理员。');
	    }
    } else {
    	sys_msg('未设置任何商品参数，请核对。');
    }
    exit;
} else {
	$smarty->assign('ur_here', '商品参数设置');
	$smarty->assign('form_action', 'insert');
	$smarty->assign('goods_params', get_goods_params());
	$smarty->display('goods_params.tpl');
}

/**
 * 获取设置商品参数数组
 * @param   null    
 * @return  array
 */
function get_goods_params()
{
	$goods_params = array();
	if($GLOBALS['_CFG']['use_promise_delivery']) {
		$goods_params[] = array(
			'name' => 'shipping_days',
			'title' => '承诺发货天数',
			'value' => '7',
			'size' => '8',
			'show' => '1',
			'relate' => ''
		);
	}
	if($GLOBALS['_CFG']['use_auto_hot']) {
		$goods_params[] = array(
			'name' => 'statistic_days',
			'title' => '热销统计天数',
			'value' => '7',
			'size' => '8',
			'show' => '1',
			'relate' => 'hot_number'
		);
		$goods_params[] = array(
			'name' => 'hot_number',
			'title' => '热销日均销售量',
			'value' => '50',
			'size' => '8',
			'show' => '0',
			'relate' => ''
		);
	}
	return $goods_params;
}

?>